{{ extend '../pub/template.html'}}

{{ block 'user-name' }}
当前登录用户{{msg}}&nbsp;&nbsp;用户角色：{{role == 'on' ? '管理员':'普通人'}}
{{ /block }}

{{ block 'user-position'}}
<nav aria-label="breadcrumb">
  <ol class="breadcrumb">
    <li class="breadcrumb-item"><a href="/admin/user">首页</a></li>
    <li class="breadcrumb-item"><a>校园公告管理</a></li>
    <li class="breadcrumb-item active" aria-current="page">添加公告</li>
  </ol>
</nav>

<div class="card border-0" style="margin: 16px;padding: 16px;min-height: 400px;">
  <form method="POST" action="/admin/noticeAdd" id="userForm">
    <!-- 公告标题 -->
    <div class="form-group ">
      <label for="staticEmail" class="col-sm-2 col-form-label col-form-label-sm">标题</label>
      <div class="col-sm-10">
        <input type="text" class="form-control form-control-sm" name="title" id="staticTitle">
      </div>
    </div>

    <!-- 公告作者 -->
    <div class="form-group ">
      <label for="inputAuthor" class="col-sm-2 col-form-label col-form-label-sm">作者</label>
      <div class="col-sm-10">
        <input type="text" class="form-control form-control-sm" name="author" id="inputAuthor" value="{{msg}}">
      </div>
    </div>

    <!-- 公告内容 -->
    <div class="form-group">
      <label for="editor" class="col-sm-2 col-form-label col-form-label-sm">公告内容</label>
      <div class="col-sm-12">
        <textarea class="form-control" id="editor" rows="3" name="content">...</textarea>
      </div>
    </div>

    <!-- 提交按钮 -->
    <div class="form-group">
      <div class="col-sm-10"><button type="submit" class="btn btn-primary">提交</button></div>
    </div>

  </form>
</div>

{{ /block}}

{{block 'script'}}
  <!-- 富文本编辑器 -->
<script src="/js/HandyEditor.min.js"></script>
<script>
  var he = HE.getEditor('editor');//其中的editor是文本输入框(textarea)的id
  $('#userForm').on('submit', function () {
    if ($('#staticTitle').val().trim().length == 0) {
      alert('请输入新闻标题')
      return false;
    } else if ($('#inputAuthor').val().trim().length == 0) {
      alert('禁止修改作者')
      return false;
    } else if ($('#editor').val().trim().length == 0) {
      alert('内容不能为空')
      return false;
    }
    // 将富文本编辑器里面的内容转换为html标签，然后同步到文本域标签中
    he.sync(he.getHtml());

  })
</script>
{{/block}}